//
//  TrainTableViewController.swift
//  约健
//
//  Created by tyh on 2017/9/14.
//  Copyright © 2017年 tyh. All rights reserved.
//

import UIKit

class TrainTableViewController: UITableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
        self.navigationController?.navigationBar.shadowImage = UIImage()
        self.navigationController?.navigationBar.isTranslucent = true
        automaticallyAdjustsScrollViewInsets = false
        self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.darkGray]
        self.navigationController?.navigationBar.tintColor = UIColor.darkGray
    
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
      
    }

    override func numberOfSections(in tableView: UITableView) -> Int {
   
        return 5
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

        return 1
    }

    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        var basecell = UITableViewCell()
        if indexPath.section == 0{
            let cell:HeadScrollViewTableViewCell = tableView.dequeueReusableCell(withIdentifier: "HeadScrollCell", for: indexPath) as! HeadScrollViewTableViewCell
            
            basecell = cell
        }
        else if indexPath.section == 1{
            let cell:AddCourseTableViewCell = tableView.dequeueReusableCell(withIdentifier: "AddCell", for: indexPath) as! AddCourseTableViewCell
            cell.TittleLabel.text = "推荐课程"
            cell.Addbutton.setTitle("+加入课程", for: .normal)
            cell.Addbutton.addTarget(self, action: #selector(addcourse), for: .touchUpInside)
            cell.bjimageView.image = UIImage(named: "addcourse.jpg")
            cell.ContentLabel.text = "不够了解自己？海量课程等着你"
            
            
            basecell = cell
            
        }else if indexPath.section == 2{
             if user_id == "-1"{
              let cell:MeThingTableViewCell = tableView.dequeueReusableCell(withIdentifier: "MeThingCell", for: indexPath) as! MeThingTableViewCell
            cell.TittleLabel.text = "我的课程"
            cell.LoginBtn.setTitle("登录", for: .normal)
            cell.LoginBtn.addTarget(self, action: #selector(GoLogin), for: .touchUpInside)
                basecell = cell
            }else{
                let cell = NoDataTableViewCell.creatCell(tableView)
                cell.JieShiText.text = "暂无关注课程"
                cell.Pic.image = UIImage(named: "没有数据.png")
                basecell = cell
            }

            
        }
        else if indexPath.section == 3{
            let cell:AddCourseTableViewCell = tableView.dequeueReusableCell(withIdentifier: "AddCell", for: indexPath) as! AddCourseTableViewCell
            cell.TittleLabel.text = "推荐俱乐部"
            cell.Addbutton.setTitle("+加入俱乐部", for: .normal)
            cell.Addbutton.addTarget(self, action: #selector(addclub), for: .touchUpInside)
            cell.bjimageView.image = UIImage(named: "addclub.jpg")
            cell.ContentLabel.text = "一个人无法坚持下去？快来俱乐部"
            
            basecell = cell
        }else{
            if user_id == "-1"{
            let cell:MeThingTableViewCell = tableView.dequeueReusableCell(withIdentifier: "MeThingCell", for: indexPath) as! MeThingTableViewCell
            cell.TittleLabel.text = "我的俱乐部"
            cell.LoginBtn.setTitle("登录", for: .normal)
            cell.LoginBtn.addTarget(self, action: #selector(GoLogin), for: .touchUpInside)
            basecell = cell
             }else{
                let cell = NoDataTableViewCell.creatCell(tableView)
                cell.JieShiText.text = "暂无关注俱乐部"
                cell.Pic.image = UIImage(named: "没有数据.png")
                basecell = cell

            }
            }
        basecell.selectionStyle = UITableViewCellSelectionStyle.none
        return basecell
    }
    
    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        if indexPath.section == 0{
            return height * 0.3
        }
        else if indexPath.section == 2 || indexPath.section == 4{
            return height * 0.2
        }else{
      return height * 0.25
        }
    }
    override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
            return 5
    }


    func addcourse(){
        self.performSegue(withIdentifier: "toselectcourse", sender: nil)
        
    }
    func addclub(){
        self.performSegue(withIdentifier: "toselectclub", sender: nil)
    }
    func GoLogin(){
        let loginview = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "LoginView")
        self.present(loginview, animated: true, completion: nil)
    }

}
